/* eslint-disable */
import { deepMerge } from '../utils'

const field = () => ({
  item: {
    label: '字段'
  },
  widget: {
    virtualTag: 've-input',
    field: 'widget.field',
    props: {
      placeholder: '请输入字段'
    }
  }
})
const labelName = () => ({
  item: {
    label: '字段描述'
  },
  widget: {
    virtualTag: 've-input',
    field: 'item.label',
    attrs: {
      placeholder: '请输入字段描述'
    }
  }
})
const colSpan = () => ({
  item: {
    label: '组件栅格'
  },
  widget: {
    virtualTag: 've-slider',
    field: 'col.span',
    valueType: 'number',
    props: {
      // min: 1, // 有bug 最大值变成25
      max: 24,
      step: 2,
      defaultValue: 24,
      showStops: true
    }
  }
})
const className = () => ({
  item: {
    label: 'class'
  },
  widget: {
    virtualTag: 've-input',
    field: 'widget.className',
    attrs: {
      placeholder: '请输入class'
    }
  }
})
const nativeId = () => ({
  item: {
    label: '原生ID'
  },
  widget: {
    virtualTag: 've-input',
    field: 'widget.attrs.id',
    attrs: {
      placeholder: '请输入原生标签ID'
    }
  }
})
// eslint-disable-next-line
const nativeTag = () => ({
  item: {
    label: '原生标签'
  },
  widget: {
    virtualTag: 've-input',
    field: 'widget.tag',
    attrs: {
      placeholder: '请输入原生标签'
    }
  }
})
const disabled = () => ({
  item: {
    label: '是否禁用'
  },
  widget: {
    virtualTag: 've-switcher',
    field: 'widget.props.disabled',
    valueType: 'boolean'
  }
})
const readonly = () => ({
  item: {
    label: '是否只读'
  },
  widget: {
    virtualTag: 've-switcher',
    field: 'widget.props.readonly',
    valueType: 'boolean'
  }
})
const required = () => ({
  item: {
    label: '是否必填'
  },
  widget: {
    virtualTag: 've-switcher',
    field: 'item.required',
    valueType: 'boolean'
  }
})
const defaultValue = () => ({
  item: {
    label: '默认值'
  },
  widget: {
    virtualTag: 've-input',
    field: 'widget.props.defaultValue',
    attrs: {
      placeholder: '请输入默认值'
    }
  }
})
const placeholder = () => ({
  item: {
    label: '占位符'
  },
  widget: {
    virtualTag: 've-input',
    field: 'widget.attrs.placeholder',
    attrs: {
      placeholder: '占位符',
    }
  }
})
const clearable = () => ({
  item: {
    label: '是否可清空'
  },
  widget: {
    virtualTag: 've-switcher',
    field: 'widget.props.clearable',
    valueType: 'boolean'
  }
})
const minValue = () => ({
  item: {
    label: '最小值'
  },
  widget: {
    virtualTag: 've-stepper',
    field: 'widget.props.min',
    valueType: 'number',
    attrs: {
      placeholder: '最小值',
    }
  }
})
const maxValue = () => ({
  item: {
    label: '最大值'
  },
  widget: {
    virtualTag: 've-stepper',
    field: 'widget.props.max',
    valueType: 'number',
    attrs: {
      placeholder: '最大值',
    }
  }
})
const multiple = () => ({
  item: {
    label: '是否多选'
  },
  widget: {
    virtualTag: 've-stepper',
    field: 'widget.props.multiple',
    valueType: 'boolean'
  }
})
const minMultiple = () => ({
  item: {
    label: '最少选几个'
  },
  widget: {
    virtualTag: 've-stepper',
    field: 'widget.props.min',
    valueType: 'number',
    attrs: {
      placeholder: '最少选几个',
    }
  }
})
const maxMultiple = () => ({
  item: {
    label: '最多选几个'
  },
  widget: {
    virtualTag: 've-stepper',
    field: 'widget.props.max',
    valueType: 'number',
    attrs: {
      placeholder: '最多选几个',
    }
  }
})
const styleType = () => ({
  item: {
    label: '样式类型'
  },
  widget: {
    virtualTag: 've-radio',
    field: 'widget.props.type',
    props: {
      defaultValue: 'normal'
    }
  },
  dict: {
    list: [
      { value: 'normal', label: '默认' },
      { value: 'button', label: '按钮' }
    ]
  }
})
const maxlength = () => ({
  item: {
    label: '字数限制'
  },
  widget: {
    virtualTag: 've-stepper',
    field: 'widget.props.maxlength',
    valueType: 'number',
    attrs: {
      placeholder: '字数限制',
    }
  }
})
const showWordLimit = () => ({
  item: {
    label: '字数统计'
  },
  widget: {
    virtualTag: 've-switcher',
    field: 'widget.props.showWordLimit',
    valueType: 'boolean'
  }
})
const prefix = () => ({
  item: {
    label: '前缀'
  },
  widget: {
    virtualTag: 've-input',
    field: 'slots.prepend.value',
    attrs: {
      placeholder: '请输入前缀'
    }
  }
})
const suffix = () => ({
  item: {
    label: '后缀'
  },
  widget: {
    virtualTag: 've-input',
    field: 'slots.append.value',
    attrs: {
      placeholder: '请输入后缀'
    }
  }
})
const dateFormat = () => ({
  item: {
    label: '日期格式'
  },
  widget: {
    virtualTag: 've-input',
    field: 'widget.props.format',
    attrs: {
      placeholder: '请输入日期格式'
    }
  }
})
const dictDivider = () => ({
  col: {
    style: {
      'margin-bottom': '18px'
    }
  },
  item: {
    label: '字典表'
  },
  widget: {
    virtualTag: 've-divider',
    tagType: 'CUSTOM',
    props: {
      contentPosition: 'left'
    }
  }
})
const dictOrg = () => ({
  item: {
    label: '数据来源'
  },
  widget: {
    virtualTag: 've-select',
    field: 'dict.type',
    props: {
      defaultValue: 'LOCAL'
    },
    on: {
      input({ value, vm, callback }) {
        if (value === 'LOCAL') {
          vm.hide('dict.fetch.params', 'dict.fetch.url', 'dict.fetch.method')
          vm.show('dict.list')
        } else if (value === 'INTERFACE') {
          vm.hide('dict.list')
          vm.show('dict.fetch.params', 'dict.fetch.url', 'dict.fetch.method')
        }
        callback()
      }
    }
  },
  dict: {
    list: [
      { label: '本地数据', value: 'LOCAL' },
      { label: '接口获取', value: 'INTERFACE' }
    ]
  }
})
const dictList = () => ({
  item: {
    label: '字典列表',
  },
  widget: {
    virtualTag: 've-dict',
    field: 'dict.list',
    tagType: 'CUSTOM'
  }
})
const dictKey = () => ({
  item: {
    label: '字典KEY'
  },
  widget: {
    virtualTag: 've-input',
    field: 'dict.label',
    attrs: {
      placeholder: '字典KEY'
    }
  }
})
const dictValue = () => ({
  item: {
    label: '字典VALUE'
  },
  widget: {
    virtualTag: 've-input',
    field: 'dict.value',
    attrs: {
      placeholder: '字典VALUE'
    }
  }
})

const dictFetchParams = () => ({
  hidden: true,
  item: {
    label: '请求参数列表',
    labelWidth: 0,
  },
  widget: {
    virtualTag: 've-dict',
    field: 'dict.fetch.params',
    tagType: 'CUSTOM'
  }
})

const dictFetchUrl = () => ({
  hidden: true,
  item: {
    label: '请求接口',
  },
  widget: {
    virtualTag: 've-input',
    field: 'dict.fetch.url',
    attrs: {
      placeholder: '请输入地址'
    },
  }
})
const dictFetchMethod = () => ({
  hidden: true,
  item: {
    label: '请求方法',
  },
  widget: {
    virtualTag: 've-input',
    field: 'dict.fetch.method',
    attrs: {
      placeholder: '请输入地址'
    },
  }
})
const nativeAttrs = () => ({
  item: {
    label: '原生属性',
  },
  widget: {
    virtualTag: 've-json',
    field: 'widget.attrs',
    attrs: {
      placeholder: '请输入原生属性'
    },
  }
})
/*
组件
*/
const radio = [
  field(),
  labelName(),
  colSpan(),
  className(),
  nativeId(),
  disabled(),
  required(),
  styleType(),
  defaultValue(),
  dictDivider(),
  dictOrg(),
  dictKey(),
  dictValue(),
  dictList(),
  dictFetchUrl(),
  dictFetchMethod(),
  dictFetchParams(),
  nativeAttrs(),
]
const checkbox = [
  field(),
  labelName(),
  colSpan(),
  className(),
  nativeId(),
  disabled(),
  required(),
  styleType(),
  {
    item: {
      label: '默认值'
    },
    widget: {
      virtualTag: 've-json',
      field: 'widget.props.defaultValue',
      attrs: {
        placeholder: '请输入默认值'
      }
    }
  },
  dictDivider(),
  dictOrg(),
  dictKey(),
  dictValue(),
  dictList(),
  dictFetchUrl(),
  dictFetchMethod(),
  dictFetchParams(),
]
const input = [
  field(),
  labelName(),
  colSpan(),
  className(),
  nativeId(),
  placeholder(),
  clearable(),
  disabled(),
  readonly(),
  required(),
  defaultValue(),
  maxlength(),
  showWordLimit(),
  prefix(),
  suffix()
]
const textarea = [
  field(),
  labelName(),
  colSpan(),
  className(),
  nativeId(),
  placeholder(),
  clearable(),
  disabled(),
  readonly(),
  required(),
  defaultValue(),
  maxlength(),
  showWordLimit()
]
const password = [
  field(),
  labelName(),
  colSpan(),
  className(),
  nativeId(),
  placeholder(),
  clearable(),
  disabled(),
  required(),
  maxlength()
]
const stepper = [
  field(),
  labelName(),
  colSpan(),
  className(),
  nativeId(),
  placeholder(),
  clearable(),
  disabled(),
  required(),
  defaultValue(),
  minValue(),
  maxValue()
]
const select = [
  field(),
  labelName(),
  colSpan(),
  className(),
  nativeId(),
  placeholder(),
  clearable(),
  disabled(),
  required(),
  defaultValue(),
  multiple(),
  minMultiple(),
  maxMultiple(),
  dictDivider(),
  dictOrg(),
  dictKey(),
  dictValue(),
  dictList(),
  dictFetchUrl(),
  dictFetchMethod(),
  dictFetchParams(),
]
const cascader = [
  field(),
  labelName(),
  colSpan(),
  className(),
  nativeId(),
  placeholder(),
  clearable(),
  disabled(),
  required(),
  defaultValue(),
  multiple(),
  minMultiple(),
  maxMultiple(),
  dictDivider(),
  dictOrg(),
  dictKey(),
  dictValue(),
  {
    item: {
      label: '字典列表',
      labelWidth: 0,
    },
    widget: {
      virtualTag: 've-json',
      field: 'dict.list',
      tagType: 'CUSTOM'
    }
  },
  dictFetchUrl(),
  dictFetchMethod(),
  dictFetchParams(),
]
const switcher = [
  field(),
  labelName(),
  colSpan(),
  className(),
  nativeId(),
  clearable(),
  disabled(),
  {
    item: {
      label: '开启描述'
    },
    widget: {
      virtualTag: 've-input',
      field: 'widget.props.activeText',
      props: {
        placeholder: '请输入开启描述'
      }
    }
  },
  {
    item: {
      label: '关闭描述'
    },
    widget: {
      virtualTag: 've-input',
      field: 'widget.props.inactiveText',
      props: {
        placeholder: '请输入关闭描述'
      }
    }
  }
]
const slider = [
  field(),
  labelName(),
  colSpan(),
  className(),
  nativeId(),
  clearable(),
  disabled(),
  defaultValue(),
  minValue(),
  maxValue()
]
const datePicker = [
  field(),
  labelName(),
  colSpan(),
  className(),
  nativeId(),
  clearable(),
  disabled(),
  defaultValue(),
  dateFormat()
]
const buttonGroup = [
  labelName(),
  colSpan(),
  className(),
  {
    item: {
      label: '按钮位置'
    },
    widget: {
      virtualTag: 've-radio',
      field: 'widget.props.position',
      props: {
        defaultValue: 'left'
      }
    },
    dict: {
      list: [
        { value: 'left', label: '左' },
        { value: 'center', label: '中' },
        { value: 'right', label: '右' }
      ]
    }
  },
  {
    item: {
      label: '按钮列表'
    },
    widget: {
      virtualTag: 've-divider',
      tagType: 'CUSTOM',
      props: {
        contentPosition: 'left'
      }
    }
  },
  {
    item: {
      label: '',
      labelWidth: 0,
    },
    widget: {
      virtualTag: 've-button-option',
      field: 'buttonGroup',
      tagType: 'CUSTOM'
    }
  },
]
const divider = [
  labelName(),
  {
    item: {
      label: '位置'
    },
    widget: {
      virtualTag: 've-radio',
      field: 'widget.props.contentPosition',
      props: {
        defaultValue: 'left'
      }
    },
    dict: {
      list: [
        { value: 'left', label: '左' },
        { value: 'center', label: '中' },
        { value: 'right', label: '右' }
      ]
    }
  }
]
const quillEditor = [
  field(),
  labelName(),
  colSpan(),
  className(),
  nativeId(),
]
const title = [
  labelName(),
  colSpan(),
  className(),
  nativeId(),
]
const panel = [
  className(),
  nativeId(),
  {
    item: {
      label: '设置阴影'
    },
    widget: {
      virtualTag: 've-radio',
      field: 'widget.props.shadow',
      props: {
        defaultValue: 'always'
      }
    },
    dict: {
      list: [
        { value: 'always', label: '总是显示' },
        { value: 'hover', label: '鼠标悬浮时显示' },
        { value: 'never', label: '从不显示' }
      ]
    }
  }
]
const table = [
  field(),
  labelName(),
  colSpan(),
  className(),
  nativeId(),
  {
    item: {
      label: '表格列label'
    },
    widget: {
      virtualTag: 've-input',
      field: 'table.label',
      props: {
        placeholder: '请输入'
      }
    }
  },
  {
    item: {
      label: '表格列prop'
    },
    widget: {
      virtualTag: 've-input',
      field: 'table.prop',
      props: {
        placeholder: '请输入'
      }
    }
  },
  {
    item: {
      label: '表格列配置',
      labelWidth: 0,
    },
    widget: {
      virtualTag: 've-json',
      field: 'table.columns',
      tagType: 'CUSTOM'
    }
  },
]
const custom = [
  field(),
  labelName(),
  className(),
  nativeId(),
  {
    item: {
      label: '组件(标签)名',
    },
    widget: {
      virtualTag: 've-input',
      field: 'widget.tag',
      props: {
        defaultValue: 'div'
      }
    }
  },
]
const componentsForm = (key) => ({
  radio,
  checkbox,
  input,
  textarea,
  password,
  quillEditor,
  stepper,
  select,
  cascader,
  switcher,
  slider,
  datePicker,
  buttonGroup,
  title,
  divider,
  panel,
  custom,
  table
})[key]

export default (key) => {
  return {
    formProps: {
      labelWidth: 70,
      // labelPosition: 'left'
    },
    rules: {},
    elements: componentsForm(key)
  }
}
